package com.cxb.springboot.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;

/**
 * @Classname ZookeeperWatcherListener
 * @Date 2023/3/28 23:11
 * @Created by Administrator
 * @Description CuratorCacheListener：替代了上面三种监听方式。
 */
@Slf4j
public class MyCuratorCacheListener implements CuratorCacheListener {

    @Override
    public void event(Type type, ChildData oldData, ChildData data) {
        if (oldData != null && oldData.getData() != null && data != null && data.getData() != null) {
            System.out.println("事件类型: " + type + " :oldData: " + new String(oldData.getData()) + " :data: " + new String(data.getData()));
        } else {
            System.out.println("event type: " + type );
        }
    }
}